<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Models\Traits;

/**
 *
 * @author Administrator
 */
trait ScopeCompanySite {
    
    public $companyField = "Co_ID";

    public $siteField = "scope";
    
    public function getCompanyField() {
        return $this->companyField;
    }
    
    public function getSiteField() {
        return $this->siteField;
    }
        
    //公司查询
    public function scopeCompany($query, $cid) {
        if($cid) {
            $query->where($this->getCompanyField(), $cid);
        }
        return $query;
    }

    //公司查询
    public function scopeSearchCompany($query, $cid) {
        if($cid) {
            $query->where($this->getCompanyField(), $cid);
        }
        return $query;
    }
    
    //站点查询
    public function scopeSite($query, $sid) {
        if($sid) {
            $query->where($this->getSiteField(), $sid);
        }
        return $query;
    }
    
}
